import Common from '../common'
var Js = Common('bonus')
export default {
	name: 'bonus',
	mixins: [Js],
	components: {},
	data() {
		return {
			fields: [{
					key: 'id',
					label: 'ID',
					application: [],
					componentName: 'sls-input',
					listType: '',
					width: 50
				},
				{
					key: 'count',
					label: '金额',
					application: [],
					componentName: 'sls-input',
					listType: 'normal',
				},
				{
					key: 'trade_info',
					label: '流水备注',
					application: [],
					componentName: 'sls-input',
					listType: 'normal',
					header_search: {
						componentName: 'sls-input',
						placeholder: '请输入备注信息',
						clearable: true,
						changeFunc: function(val, self) {
							if (val) {
								self.searchItem.trade_info = ['LIKE',['%'+val+'%']];
							} else {
								delete self.searchItem.trade_info;
							};
						},
					},
				},
				{
					key: 'user_no',
					label: '用户NO',
					application: [],
					componentName: 'sls-input',
					listType: 'normal',
					header_search: {
						componentName: 'sls-input',
						placeholder: '请输入用户NO',
						clearable: true,
						changeFunc: function(val, self) {
							if (val) {
								self.searchItem.user_no = ['LIKE',['%'+val+'%']];
							} else {
								delete self.searchItem.user_no;
							};
						},
					},
					width:180
				},
				{
					key: 'nickname',
					label: '用户昵称',
					application: [],
					componentName: 'sls-input',
					listType: 'normal',
					formatter: function(val, tests) {
						return val.user.nickname ? val.user.nickname : '';
					},
					header_search: {
						componentName: 'sls-input',
						placeholder: '请输入用户昵称',
						changeFunc: function(e, self) {
							if (e) {
								self.User.searchItem.nickname = ['LIKE', ['%' + e + '%']]
							} else {
								delete self.User.searchItem.nickname
							};
							self.beforeSearch('User');
						},
					},
					width:150
				},
				{
					key: 'login_name',
					label: '用户手机号',
					application: [],
					componentName: 'sls-input',
					listType: 'normal',
					formatter: function(val, tests) {
						return val.user.login_name ? val.user.login_name : '';
					},
					header_search: {
						componentName: 'sls-input',
						placeholder: '请输入用户手机号',
						changeFunc: function(e, self) {
							if (e) {
								self.User.searchItem.login_name = ['LIKE', ['%' + e + '%']]
							} else {
								delete self.User.searchItem.login_name
							};
							self.beforeSearch('User');
						},
					},
					width:150
				},
				{
					key: "status",
					label: '状态',
					application: [],
					componentName: 'sls-select',
					optionsName: 'statusOptions',
					defaultProps: {
						label: 'text',
						value: 'value',
					},
					formatter: function(val) {
						if (val.status == 1) {
							return '启用';
						} else {
							return '关闭';
						};
					}
				},
				{
					key: 'create_time',
					label: '创建时间',
					listType: 'normal',
					placeholder: '请选择创建时间',
					header_search: {
						componentName: 'sls-date-time-range',
						style: 'width:160px;margin-right:2px;',
						start_placeholder: '创建开始时间',
						end_placeholder: '创建结束时间',
						changeFunc: function(value, self) {
							if (!value) {
								delete self.searchItem.create_time;
							} else {
								self.searchItem.create_time = ['between', value = value.map(function(e) {
									return e / 1000;
								})]
							};
							
						},
					},
					width: 200,
				},
				{
					label: '操作',
					listType: 'deal',
					width: 200
				},
			],
			// 按钮配置
			btn_info: [


				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'list',
					text: function(data) {
						return '编辑'
					},
					func: {
						apiName: function(self) {
							return "api_flowLogUpdate"
						},
						formData: function(self) {
							return self.formData
						},
						postData: function(self) {
							var postData = {
								searchItem: {
									id: self.formData.id,
									user_type: 0,
								},
								data: self.submitData
							};
							return postData;
						}
					},
				},
				{
					type: 'danger',
					icon: 'delete',
					size: 'mini',
					funcType: 'submit',
					position: 'header',
					text: function(data) {
						return '删除选中'
					},
					func: {
						apiName: function(self) {
							return "api_flowLogUpdate"
						},
						postData: function(self) {
							var deleteArray = [];
							for (var i = 0; i < self.selectionArray.length; i++) {
								deleteArray.push(self.selectionArray[i].id);
							};
							var postData = {
								searchItem: {
									id: ['in', deleteArray],
									user_type: 0,
								},
								data: {
									status: -1
								}
							};
							return postData;
						}
					},
				},
				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'header',
					text: function(data) {
						return '添加'
					},
					func: {
						apiName: function(self) {
							return "api_flowLogAdd"
						},
						formData: function(self) {
							return data
						},
						postData: function(self) {
							self.submitData.type = 2;
							self.submitData.user_type = 1;
							var postData = {
								data: self.submitData
							};
							return postData;
						}
					},
				},

			],

			searchItem: {
				type: 9
			},
			startSearchItem: {
				type: 9
			},
			optionData: {
				statusOptions: [{
					text: '启用',
					value: 1
				}, {
					text: '禁用',
					value: -1
				}],
			},
			otherData: {},
			UserInfo: {
				tableName: 'UserInfo',
				searchItem: {},
				key: 'user_no',
				middleKey: 'user_no',
				condition: 'in',
			},
			User: {
				tableName: 'User',
				searchItem: {},
				key: 'user_no',
				middleKey: 'user_no',
				condition: 'in',
			}

		}

	},

	mounted() {
		const self = this;
		 
		this.init()
	},
	computed: {
		token: function() {
			return this.$store.getters.getToken
		}
	},
	methods: {

		/**
		 * 初始化
		 */
		init() {
			this.initMainData();
		},



		/**
		 * 列表主函数
		 */
		async initMainData(isNew) {

			const self = this;
			const postData = {};
			if (isNew) {
				self.paginate.currentPage = 1;
			};
			postData.paginate = self.$$cloneForm(self.paginate);
			postData.token = self.$store.getters.getToken;
			if (self.searchItem) {
				postData.searchItem = self.$$cloneForm(self.searchItem)
			};
			if (JSON.stringify(self.getBefore) != "{}") {
				postData.getBefore = self.$$cloneForm(self.getBefore);
			};
			postData.getAfter = {
				user: {
					tableName: 'User',
					middleKey: 'user_no',
					key: 'user_no',
					condition: '=',
					searchItem: {
						status: 1
					},
					info: ['nickname', 'info'],
				},
			};

			var res = await self.$$api_flowLogGet({
				data: postData
			});
			self.mainData = res.info.data;
			self.paginate.count = res.info.total;

		}

	},


}
